//
//  AddGroupHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/6/17.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AddGroupHeaderView.h"
#import "AddGroupChatHeaderCell.h"

@interface AddGroupHeaderView ()<UICollectionViewDelegate,UICollectionViewDataSource>
/**
 collectionView
 */
@property (nonatomic , strong) UICollectionView *collectionView;
/**
 search
 */
@property (nonatomic , strong) UISearchBar *searchView;
/**
 item
 */
@property (nonatomic , strong) NSMutableArray *itemArr;

@end
@implementation AddGroupHeaderView
#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initData];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.collectionView];
}

- (void)initLayout {
    // 布局子控件
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}
- (void)initData {
}
#pragma mark - delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    AddGroupChatHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AddGroupChatHeaderCellID" forIndexPath:indexPath];
    Friends *model = self.dataArr[indexPath.item];
    [cell configCellWithModel:model];
    return cell;
}
#pragma mark - getter and setter
- (void)setDataArr:(NSMutableArray *)dataArr {
    _dataArr = dataArr;
    [self.collectionView reloadData];
}
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(46, 46);
        flowLayout.minimumLineSpacing = 2.0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        [_collectionView registerClass:[AddGroupChatHeaderCell class] forCellWithReuseIdentifier:@"AddGroupChatHeaderCellID"];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
        
    }
    return _collectionView;
}

@end
